package cn.yh.shop.admin.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.yh.shop.admin.dao.AdminRoleDao;
import cn.yh.shop.admin.service.IAdminRoleService;

/** 
*@Description:TODO
* @author  "许荣斐"
* @time:2016年12月20日 下午2:17:59
* @version 1.0 
*/
@Service("adminRoleService")
public class AdminRoleServiceImpl implements IAdminRoleService {

	@Autowired
	private AdminRoleDao adminRoleDao;

	@Override
	public void saveOrUpdate(Integer userId, List<Integer> roleIdList) {
		if(roleIdList.size() == 0){
			return ;
		}
		
		//先删除用户与角色关系
		adminRoleDao.delete(userId);
		
		//保存用户与角色关系
		Map<String, Object> map = new HashMap<>();
		map.put("userId", userId);
		map.put("roleIdList", roleIdList);
		adminRoleDao.save(map);
	}

	@Override
	public List<Integer> queryRoleIdList(Integer userId) {
		return adminRoleDao.queryRoleIdList(userId);
	}

	@Override
	public void delete(Integer userId) {
		adminRoleDao.delete(userId);
	}

}
